package com.example.elderlycare.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.elderlycare.dao.entity.Common;
import com.example.elderlycare.dao.mapper.CommonMapper;
import com.example.elderlycare.service.CommonService;
import com.example.elderlycare.service.entity.CommonItem;
import com.example.elderlycare.service.entity.CommonListResponseBody;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class CommonServiceImpl extends ServiceImpl<CommonMapper, Common> implements CommonService {

    @Resource
    CommonMapper commonMapper;

    public CommonListResponseBody getCommonListByTypeId(int id) {
        List<CommonItem> commonItemList = new ArrayList<>();
        QueryWrapper<Common> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type", id);
        List<Common> commons = commonMapper.selectList(queryWrapper);
        int total = Math.toIntExact(commonMapper.selectCount(queryWrapper));
        for (Common common : commons) {
            CommonItem commonItem = CommonItem.builder().id(common.getId()).name(common.getName()).build();
            commonItemList.add(commonItem);
        }
        return CommonListResponseBody.builder().total(total).commonItemList(commonItemList).build();
    }

    @Override
    public CommonListResponseBody getEmployeeStatusList() {
        return getCommonListByTypeId(1);
    }

    @Override
    public CommonListResponseBody getEmployeeEducationList() {
        return getCommonListByTypeId(2);
    }

    @Override
    public CommonListResponseBody getCertificateList() {
        return getCommonListByTypeId(3);
    }

    @Override
    public CommonListResponseBody getEquipmentTypeList() {
        return getCommonListByTypeId(4);
    }

    @Override
    public CommonListResponseBody getIssueList() {
        return getCommonListByTypeId(5);
    }

    @Override
    public CommonListResponseBody getDepartmentList() {
        return getCommonListByTypeId(6);
    }

    @Override
    public CommonListResponseBody getPositionList() {
        return getCommonListByTypeId(7);
    }

    @Override
    public CommonListResponseBody getRelationList() {
        return getCommonListByTypeId(8);
    }

    @Override
    public CommonListResponseBody getEquipmentStatusList() {
        return getCommonListByTypeId(9);
    }

    @Override
    public CommonListResponseBody getAwardsTypeList() {
        return getCommonListByTypeId(10);
    }

    @Override
    public CommonListResponseBody getCheckInStatusList() {
        return getCommonListByTypeId(11);
    }

    @Override
    public CommonListResponseBody getTrainingTypeList() {
        return getCommonListByTypeId(12);
    }


    @Override
    public CommonListResponseBody getEvaluationTypeList() {
        return getCommonListByTypeId(13);
    }

    @Override
    public CommonListResponseBody getEvaluationStandardList() {
        return getCommonListByTypeId(14);
    }

    @Override
    public CommonListResponseBody getComplainWayList() {
        return getCommonListByTypeId(15);
    }

    @Override
    public CommonListResponseBody getHandleStatusList() {
        return getCommonListByTypeId(16);
    }

    @Override
    public CommonListResponseBody getReplyStatusList() {
        return getCommonListByTypeId(17);
    }

    @Override
    public CommonListResponseBody getSatisfactionList() {
        return getCommonListByTypeId(18);
    }
    @Override
    public CommonListResponseBody getConsultMethodList() {
        return getCommonListByTypeId(19);
    }

    @Override
    public CommonListResponseBody getMediaList() {
        return getCommonListByTypeId(20);
    }
}
